#include "RenderObject.h"
#include "../core/Logger.h"

namespace k2graphics
{

RenderObject::RenderObject(int renderTarget, int maxB, int maxI, int maxF)
{
	roID = 0;

	rd = new RenderData(renderTarget, maxB, maxI, maxF);
	layer = 0;
	viewportGroup = 0;
	viewportBits = 0;

	roX = 0.0f;
	roY = 0.0f;
	roHalfWidth = 0.0f;
	roHalfHeight = 0.0f;

	isLocal = false;
}

RenderObject::~RenderObject()
{
	if(rd)
		delete rd;
}

void RenderObject::setLayer(int nl)
{
	layer = nl;
}

void RenderObject::setCropPositionOnly(float x, float y)
{
	roX = x;
	roY = y;
}

void RenderObject::setCanonicalPosition(float x, float y, float theta)
{
	LOG(logDEBUG4) << "Trying to set position to " << x << " , " << y;
	roX = x;
	roY = y;
	if(rd->numFloats >= 3)
	{
		rd->floatData[0] = x;
		rd->floatData[1] = y;
		rd->floatData[2] = theta;
		LOG(logDEBUG4) << "Set position to " << x << " , " << y;
	}
	else
	{
		LOG(logERROR) << "could not set position; only " << rd->numFloats;
	}
}

void RenderObject::setBoundingBoxDims(float width, float height)
{
	roHalfWidth = width / 2.0;
	roHalfHeight = height / 2.0;
}

void RenderObject::extractCanonicalPosition()
{
	if(rd->numFloats >= 3)
	{
		roX = rd->floatData[0];
		roY = rd->floatData[1];
	}
}

}
